package com.zzq.common.util;

import org.apache.commons.codec.binary.Base64;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.util.Arrays;

/**
 * @author ZZQ
 * @date 2019/7/6 下午 9:13
 */
public class MD5Util {
    private static final String SALT = "zzq";

    public static String MD5WithSalt(String s) {
        return encoderByMD5(s + SALT);
    }

    private static String encoderByMD5(String pwd) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            return Arrays.toString(Base64.encodeBase64(md5.digest(pwd.getBytes(StandardCharsets.UTF_8))));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
